package user

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	agentClient "gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/client"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserReleaseRelationLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员管理 - 会员层级 - 解除代理
func NewUserReleaseRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserReleaseRelationLogic {
	return &UserReleaseRelationLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserReleaseRelationLogic) UserReleaseRelation(req *types.UserReleaseRelationRequest) (resp *types.UserReleaseRelationResponse, err error) {
	rpcReq := &agentClient.AgentUnbindRequest{
		UserId: req.UserId,
	}
	_, err = l.svcCtx.AgentRPC.Unbind(l.ctx, rpcReq)
	if err != nil {
		return nil, err
	}
	resp = &types.UserReleaseRelationResponse{}
	return
}
